<div class="layuimini-container layuimini-page-anim" id="openDiv">
    <div class="layuimini-main" id="tabelNew">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="" id="formOpen">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">用户名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="jobNumberSearch" autocomplete="off" class="layui-input"
                                       id="jobNumber">
                                <input id="roleNewValue" name="roleNewValue" value="" hidden>
                                <input id="xuanXiangTab" name="xuanXiangTab" value="" hidden>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="userNameSearch" autocomplete="off" class="layui-input"
                                       id="userName">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="authority-search-btn"
                                    style="margin-left:10px;width:90px;height:38px;border:none;outline:none;border-radius:6px;background-color:#007bff;color:white"><i
                                    class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <div class="layui-tab">
            <ul class="layui-tab-title">
                <li class="layui-this" lay-id="allMem" lay-filter="newSearch">所有人员</li>
                <li lay-id="checkedMem" lay-filter="newSearch">已选成员</li>
            </ul>
        </div>
        <div style="margin-top: -22px">
            <table id="memberTable" class="layui-table" lay-filter="tableSc"></table>
            <div id="page"></div>
        </div>
    </div>
</div>

<style>
    .layui-tab-title .layui-this{
        background-color: #3f7dff;
        color:#f1f4f5;
    }
</style>

<script>
    var memberTableBar = [
        { title: '序号', type: 'numbers', width: '10%', align: "center" },
        { field: 'account', title: '用户名', width: '30%', align: "center" },
        { field: 'user_name', title: '姓名', width: '20%', align: "center" },
             { title: '操作', width: '30%', align: "center" , templet:function (param) {
                 debugger
                 if($('#xuanXiangTab').val()=="已选成员"){
                     return '<a class="layui-btn layui-btn-xs layui-btn layui-btn-normal data-count-edit" lay-event="move" onclick="moveMember('+param.role_id+','+param.id+')">移除</a>'
                 }
                 else{
                     if(param.role_id == $('#roleNewValue').val()){
                         return '<input type="checkbox" lay-skin="primary" id="memberID" lay-filter="checkMem" value="'+param.id+'" checked>'
                     }
                     else{
                         return '<input type="checkbox" lay-skin="primary" id="memberID" lay-filter="checkMem" value="'+param.id+'">'
                     }
                 }
             }}
    ]

    var initMemberTableParams = {
        "account": "",
        "user_name":"",
        "orderType": "account",
        "orderValue": "asc",
        "page": 1,
        "pageSize": 10,
        "role":$('#roleNewValue').val(),
        "type":""
    }
    layuiEx.tableRender(
        "/sys-mgr/userList", //查询权限组列表
        'memberTable',
        'page',
        memberTableBar,
        initMemberTableParams
    );

    /*搜索*/
    layui.form.on('submit(authority-search-btn)',function (data) {
        debugger
        var role = $('#roleNewValue').val();
        var type = $('#xuanXiangTab').val();
        layuiEx.tableRender(
            "/sys-mgr/userList",
            'memberTable',
            'page',
            memberTableBar,
            {
                "account":$('#jobNumber').val(),
                "user_name":$('#userName').val(),
                "page":1,
                "pageSize":10,
                "role":role,
                "type":type
            }
        );
        return false
    })

    /*弹出框切换Tab*/
    $('.layui-tab-title').click(function (data) {
        var role = role= $('#roleNewValue').val();
        var type = $(data.target).text();
        constTitle = $(data.target).text();
        $('#xuanXiangTab').val(constTitle);
        layuiEx.tableRender(
            "/sys-mgr/userList",
            'memberTable',
            'page',
            memberTableBar,
            {
                "account":$('#jobNumber').val(),
                "user_name":$('#userName').val(),
                "page":1,
                "pageSize":10,
                "role":role,
                "type":type
            }
        );
    })

    /*弹出框移除已选成员*/
    function moveMember(role_id,user_id){
        shared.ajaxPost('/sys-mgr/moveMember', { "user_id": user_id,"role_id":role_id}, function callback(res) {
            debugger
            if (res) {
                layer.msg(res, {
                    icon: 1,
                    time: 1000 //2秒关闭（如果不配置，默认是3秒）
                });
            }
            layuiEx.tableRender(
                "/sys-mgr/userList",//查询权限组列表
                'memberTable',
                'page',
                memberTableBar,
                {
                    "account":$('#jobNumber').val(),
                    "user_name":$('#userName').val(),
                    "page":1,
                    "pageSize":10,
                    "role":role_id,
                    "type":"已选成员"
                }
            );
        })
    }

    layui.form.on('checkbox(checkMem)',function(data){
        var role= $('#roleNewValue').val();
        var type = "";
        var dataValue = data.value;
        if(data.elem.checked){
            type = "add";
        }
        else{
            type = "del"
        }

        shared.ajaxPost('/sys-mgr/addMember', { "user_id": dataValue,"role_id":role, "type":type}, function callback(res) {
            debugger
            if (res) {
                layer.msg(res, {
                    icon: 1,
                    time: 1000 //2秒关闭（如果不配置，默认是3秒）
                });
            }
        })
    })
</script>
